// 主界面
;
define(function(require, exports, module) {
	'use strict';
	var util = require("util");
	var base = require(CONFIG.BasePath + "js/enterprise/base");
	var router = require("../hash/pageRouter");
	var constant = require("constant");
	var css_pickup = require("./accountPickupDetail.css");
	var databind = require("databind");
	var pickupId;
	var pickupDelayId;
	var action;
	var financeId;
	var tools = require("tools");
	var init = function(page) {
		pickupId = page.params.pickupId;
		inquireNormalPickupApplicationDetail();
		router.init();
		initEvent();
	};

	var initEvent = function() {
		if (base.getData("sid") == null) {
			location.href = "../login/login.html";
		}
		//点击项目基本详情financeDetail
		$(".financeDetail").unbind("click").click(function() {
			router.route("account/accountDetail.html?financeId=" + financeId, true);

		});
		
		$("#accountPickupDetail .print").unbind("click").click(function(){
			tools.preview();
		});
	};


	//获取提货申请明细
	var inquireNormalPickupApplicationDetail = function() {
		base.fnAjax({
			action: "inquireNormalPickupApplicationDetail.json",
			oData: {
				pickupId: pickupId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					databind.fillForm($("#accountPickupDetail"), data.datas[0]);
					if ($("#pickupDetailDeliveryMethod").html() == 2) {
						$("#pickupDetailDeliveryMethod").html("到港");
					} else if ($("#pickupDetailDeliveryMethod").html() == 1) {
						$("#pickupDetailDeliveryMethod").html("到门");
					}

					if ($("#pickupDetailPickupMethod").html() == 1) {
						$("#pickupDetailPickupMethod").html("现金提货");
					} else if ($("#pickupDetailPickupMethod").html() == 2) {
						$("#pickupDetailPickupMethod").html("换货");
					} else {
						$("#pickupDetailPickupMethod").html("换箱");
					}

					juicer.register("getValueByKey", constant.getValueByKey);

					var tpl1 = $("#pickupDetailBulkstockTpl").html();
					var html1 = juicer(tpl1, data);
					$("#pickupDetailBulkstockBody").html(html1);

					var tpl2 = $("#pickupDetailInventoryTpl").html();
					var html2 = juicer(tpl2, data);
					$("#pickupDetailInventoryBody").html(html2);
					
					var tpl3 = $("#exchangeBulkstockTpl").html();
					var html3 = juicer(tpl3, data);
					$("#exchangeBulkstockTable").html(html3);
					
					var tpl4 = $("#exchangeInventoryTpl").html();
					var html4 = juicer(tpl4, data);
					$("#exchangeInventoryTable").html(html4);
					
					$.each(data.datas[0].fileUuids.split(","), function() {
						var _this = this;
						if ($.trim(_this) != "") {
							if (tools.inquireFile(_this) != "") {
								$("#accountPickupDetail .fs").append('<div class="showProductIntroDiv"><a target="_blank" class="mas" fileUuid="' + _this + '" href="/finance/api/v1.0/downloadFile.file?fileUuid=' + _this + '" class="showProductIntro">' + tools.inquireFile(_this) + '</a></div> ');
							}
						}
					});

					if ($("#pickupDetailInventoryBody").find("tr").length == 1) {
						$("#pickupDetailInventoryBody").parent().addClass("none");
					}
					if ($("#pickupDetailBulkstockBody").find("tr").length == 1) {
						$("#pickupDetailBulkstockBody").parent().addClass("none");
					}
					if ($("#exchangeInventoryTable").find("tr").length == 1) {
						$("#exchangeInventoryTable").parent().addClass("none");
					}
					if ($("#exchangeBulkstockTable").find("tr").length == 1) {
						$("#exchangeBulkstockTable").parent().addClass("none");
					}
					
					$("#accountPickupDetail .detail").unbind("click").click(function(){
						router.route("account/accountTallyDetail.html?inventoryId=" + $(this).parents("tr").attr("inventoryId"));
					});
					tools.barcode($("#accountPickupDetail .barcode"), data.datas[0].pickupNumber, "code128");
				} else {
					//                  base.alert(2,"信息获取失败");
				}
			}
		});
	};

	return {
		init: init
	};
});